import request from "./request.js"

// 登录
export let onLogin = (data) => {
    return request({
        url: "/mp/v1_0/authorizations",
        method: "POST",
        data
    })
}

// 获取用户详情
// 获取用户信息
export const getUserDetail = () => {
  
    return request({
        method: 'GET',
        url: '/mp/v1_0/user/profile',
     
    })
}

// 文章

// /mp/v1_0/articles
export const getArticle = (params) => {

    return request({
        method: 'GET',
        url: '/mp/v1_0/articles',
        params
    })
}

// 文章频道
export const getArticleChannels = () => {

    return request({
        method: 'GET',
        url: '/mp/v1_0/channels',
        
    })
}

// 删除文章
export const deleteArticle = (articleId)=>{
    return request({
        
        method: 'DELETE',
        url: '/mp/v1_0/articles/'+articleId,
    })
}

// 发布文章（增加文章）
export const addArticle = (data,draft = false)=>{
    return request({
        
        method: 'POST',
        url: '/mp/v1_0/articles',
        params:{
            draft
        },
        data
    })
}

// 编辑文章或者更新文章
export const updateArticle = (articleId,data,draft = false)=>{
    return request({
        
        method: 'PUT',
        url: '/mp/v1_0/articles/'+articleId,
        params:{
            draft
        },
        data
    })
}



// 获取文章

export const getArticleDetial = (articleId)=>{
    return request({
        
        method: 'GET',
        url: '/mp/v1_0/articles/'+articleId,
        
    })
}


// 上传图片
export const uploadImage = (data)=>{
    return request({
        
        method: 'POST',
        url: '/mp/v1_0/user/images',
        data
    })
}

// 获取素材

export const getImages = (params)=>{
    return request({
        
        method: 'GET',
        url: '/mp/v1_0/user/images',
        params
    })
}

// 收藏图片
export const collectImages = (imageId,collect)=>{
    return request({
        
        method: 'PUT',
        url: '/mp/v1_0/user/images/'+imageId,
        data:{
            collect
        }
        
    })
}

// 删除图片
export const deleteImages = (imageId)=>{
    return request({
        
        method: 'DELETE',
        url: '/mp/v1_0/user/images/'+imageId,
        
        
    })
}

// 修改评论状态
export const updateCommentStatus = (articleId,allowComment)=>{
    return request({
        
        method: 'PUT',
        url: '/mp/v1_0/comments/status',
        params:{
            article_id:articleId
        },
        data:{
            allow_comment:allowComment
        }
        
    })
}

// 修改用户头像

export const updateUserPhoto = (data)=>{
    return request({
        
        method: 'PATCH',
        url: '/mp/v1_0/user/photo',
        
        data
        
    })
}

// 修改用户的信息

export const updateUserProfile = (data)=>{
    return request({
        
        method: 'PATCH',
        url: '/mp/v1_0/user/profile',
        
        data
        
    })
}